﻿using PDFDesign.Model;

namespace PDFDesign.ViewModel
{
    public class ControlViewModel : BaseViewModel
    {
        public ControlViewModel(Control control)
        {
            Control = control;
            type = control.Type;
            name = control.Name;
            caption = control.Caption;
            showCaption = control.ShowCaption;
            origin = control.Origin;
            dataField = control.DataField;
            isPageNumber = control.IsPageNumber;
            value = control.Value;
            relativeTable = control.RelativeTable;
            top = control.Position.Top;
            left = control.Position.Left;
            width = control.Size.Width;
            height = control.Size.Height;
            textstyle = new TextStyleViewModel(control.TextStyle);
        }

        public Control Control { get; set; }

        public void Save()
        {
            Control.Type = type;
            Control.Name = name;
            Control.Caption = caption;
            Control.ShowCaption = showCaption;
            Control.Origin = origin;
            Control.DataField = dataField;
            Control.IsPageNumber = isPageNumber;
            Control.Value = value;
            Control.RelativeTable = relativeTable;
            Control.Position.Top = top;
            Control.Position.Left = left;
            Control.Size.Width = width;
            Control.Size.Height = height;
            textstyle.Save();
            Control.TextStyle = textstyle.Textstyle;
        }

        private ControlType type = ControlType.text;
        public ControlType Type
        {
            get => type;
            set
            {
                type = value;
                OnPropertyChanged("Type");
            }
        }

        private string name;
        public string Name
        {
            get => name;
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }

        private string caption;
        public string Caption
        {
            get => caption;
            set
            {
                caption = value;
                OnPropertyChanged("Caption");
            }
        }

        private bool showCaption;
        public bool ShowCaption
        {
            get => showCaption;
            set
            {
                showCaption = value;
                OnPropertyChanged("ShowCaption");
            }
        }

        private DataOrigin origin = DataOrigin.value;
        public DataOrigin Origin
        {
            get => origin;
            set
            {
                origin = value;
                OnPropertyChanged("Origin");
            }
        }

        private string dataField;
        public string DataField
        {
            get => dataField;
            set
            {
                dataField = value;
                OnPropertyChanged("DataField");
            }
        }

        private bool isPageNumber;
        public bool IsPageNumber
        {
            get => isPageNumber;
            set
            {
                isPageNumber = value;
                OnPropertyChanged("IsPageNumber");
            }
        }

        private string value;
        public string Value
        {
            get => value;
            set
            {
                this.value = value;
                OnPropertyChanged("Value");
            }
        }

        private bool relativeTable;
        public bool RelativeTable
        {
            get => relativeTable;
            set
            {
                relativeTable = value;
                OnPropertyChanged("RelativeTable");
            }
        }

        private double top;
        public double Top
        {
            get => top;
            set
            {
                top = value;
                OnPropertyChanged("Top");
            }
        }

        private double left;
        public double Left
        {
            get => left;
            set
            {
                left = value;
                OnPropertyChanged("Left");
            }
        }

        private double width;
        public double Width
        {
            get => width;
            set
            {
                width = value;
                OnPropertyChanged("Width");
            }
        }

        private double height;
        public double Height
        {
            get => height;
            set
            {
                height = value;
                OnPropertyChanged("Height");
            }
        }

        private TextStyleViewModel textstyle;
        public TextStyleViewModel Textstyle
        {
            get => textstyle;
            set
            {
                textstyle = value;
                OnPropertyChanged("Textstyle");
            }
        }
    }
}
